package com.qbccn.usercenter.config;

import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @author linke
 * @date 2020/5/24 22:31
 * @description
 */
//如果返回的是Json格式的数据，
//可以使用@ResponseBody+@ControllerAdvice、@RestControllerAdvice
@RestControllerAdvice
//@ControllerAdvice
public class ExceptionPageConfig {

    //捕获异常
    @ExceptionHandler(value = AccessDeniedException.class)
    public ModelAndView accessDeniedException(Exception e, HttpServletRequest request) {
        System.out.println(e.getMessage());
        return new ModelAndView("error/403");
    }
}
